package com.hapoerpejb.services;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.HAPOERP_EJB.persistance.Offer;



@Stateless
public class OfferDAOImpl implements OfferDAORemote, OfferDAOLocal {

	
	@PersistenceContext
	private EntityManager em;
	
	
	
    public OfferDAOImpl() {
        
    	
    }

	@Override
	public Offer findOfferById(int id) {
		
		return em.find(Offer.class, id);
	}

	

	@SuppressWarnings("unchecked")
	@Override
	public List<Offer> findAllOffer() {
		// TODO Auto-generated method stub
		return em.createNamedQuery("Offer.findAll").getResultList();
	}

	@Override
	public void removeOffer(Offer ofe) {
		// TODO Auto-generated method stub
		em.remove(em.merge(ofe));
		
	}

	@Override
	public void updateOffer(Offer ofe) {
		// TODO Auto-generated method stub
		em.merge(ofe);
		
	}

	@Override
	public void createOffer(Offer ofe) {
		// TODO Auto-generated method stub
		em.persist(ofe);
		em.clear();
		
	}

	@Override
	public Offer findByid(String string) {
		// TODO Auto-generated method stub
		return (Offer) em.createNamedQuery("Offer.findByid").setParameter("id", string).getSingleResult();
	}
	
	
}
